﻿using Newtonsoft.Json;
using shuatibao.Tool;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace shuatibao.Web.Banner
{
    /// <summary>
    /// BannerList 的摘要说明
    /// </summary>
    public class BannerList : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            // 获取POST请求的JSON数据
            string requestJson = new StreamReader(context.Request.InputStream).ReadToEnd();

            Dictionary<string, string> parameters = JsonConvert.DeserializeObject<Dictionary<string, string>>(requestJson);
            bool show = true;

            if (parameters.Keys.Contains("show")) {
                show = Convert.ToBoolean(parameters["show"]);
            }
           
            List<BannerModel>bannerList = BannerAction.getBannerListManager(show);

            BannerListModel backModel = new BannerListModel();
            backModel.code = "200";
            backModel.msg = "";
            backModel.data = bannerList;

            Utils.jsonBackManager(context, Utils.toJSON(backModel));

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}